#include "StoryCellWidget.h"

StoryCellWidget::StoryCellWidget(QWidget *parent): QWidget(parent), ui(new Ui::StoryCellWidgetClass())
{
	ui->setupUi(this);
	resize(250, 300);
}

StoryCellWidget::~StoryCellWidget()
{
	delete ui;
}

void StoryCellWidget::setUi(StoryCellData* storyCellData)
{
	this->storyCellData = storyCellData;
}

void StoryCellWidget::mouseReleaseEvent(QMouseEvent* ev)
{
	Q_UNUSED(ev)
	emit on_storyCell_click(this);
}

void StoryCellWidget::paintEvent(QPaintEvent* ev)
{
	int w = width(), h = height(); // 250, 300
	QPainter painter(this);

	QRect picture(0, 0, w, h * 0.6);
	QPixmap pic(storyCellData->picture);
	painter.drawPixmap(picture, pic);

	QRect description(0, h * 0.6, w, h * 0.2);
	painter.drawText(description, storyCellData->description);

	QRect userAvatar(0, h * 0.8, w * 0.4, h * 0.2);
	QPixmap avatar(storyCellData->userAvatar);
	painter.drawPixmap(userAvatar, avatar);

	QRect userName(w*0.4, h * 0.9, w*0.6, h * 0.1);
	painter.drawText(userName, storyCellData->userName);
}
